<template>
    <div>
        <div class="nowrap">
            <bread-crumb></bread-crumb>
        <h1>不带头像的所有学生信息</h1>

        <el-table id="work-table" :data="tableData" style="width: 100%" border height="500px">
            <el-table-column prop="stu_id" label="学号" width="100">
            </el-table-column>
            <el-table-column prop="stu_name" label="姓名" width="100">
            </el-table-column>
            <el-table-column prop="stu_sex" label="性别" width="100">
            </el-table-column>
            <el-table-column prop="stu_date" label="出生日期" width="180">
                <template slot-scope="scope">
                    <!-- <p></p> -->
                    <!-- <p>{{ scope.$index }}</p> -->
                    <p>{{ $moment(scope.row.stu_date).format("YYYY-MM-DD") }}</p>
                </template>
            </el-table-column>


            <el-table-column prop="stu_jg" label="籍贯" width="100">
            </el-table-column>
            <el-table-column prop="stu_gbf" label="男女朋友" width="100">
            </el-table-column>


        </el-table>
        <el-button @click="exportExcel">将数据导出到本地的Excel当中</el-button>
        </div>
    </div>
</template>

<script>
//导出excel的两个包
import XLSX from "xlsx";
import FileSaver from "file-saver";
import {req_stu_info_nohead} from "@/api/stuInfo.js"
    export default {
       async mounted(){
            let result = await req_stu_info_nohead();
            console.log(result);
            this.tableData = result.data;
        },
        data(){
            return{
                tableData:[],
            }
        },
        methods:{
            exportExcel(){
                console.log("到处excel当中");
                //将table生成工作蒲，他有俩参数： 参数一：table对象
                //xlsx上面有一个utils属性  utils上面有一个table_to_book属性
                let wb = XLSX.utils.table_to_book(document.getElementById("work-table"),{
                    raw:true,
                });
                 // 根据工作簿当中的内容将其变为二进制 输出
                 let wbout = XLSX.write(wb,{
                     bookType:"xlsx",
                     bookSST:true,
                     type:"array",
                 });
                 // 将得到的二进制文件存储到Blob对象中
                 try{
                     FileSaver.saveAs(
                         new Blob([wbout],{type:"application/octet-stream"}),
                         "stuInfo.xlsx"
                     );
                 }catch(e){
                     console.log(e);
                 }

            }
        }                    
    }
</script>

<style lang="scss" scoped>
div{
    .nowrap{
        height: 30px;
    }
}

</style>